package cn.chengpengper.psi.action;

import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.psi.JavaRecursiveElementVisitor;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiMethod;
import org.jetbrains.annotations.NotNull;

public class PsiMethodGetterAction extends AnAction {
    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        StringBuilder result = new StringBuilder();

        final PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE);
        psiFile.accept(new JavaRecursiveElementVisitor() {
            @Override
            public void visitMethod(@NotNull PsiMethod method) {
                if(method.getName().startsWith("get")){
                    result.append(method.getName()).append("<br>");
                }
            }
        });
        Notifications.Bus.notify(new Notification("Print", "PSIDemo", result.toString(), NotificationType.INFORMATION), e.getProject());
    }
}
